package cn.tedu.charging.device.controller;

import cn.tedu.charging.common.pojo.param.GunStatusUpdateParam;
import cn.tedu.charging.common.pojo.vo.StationInfoVO;
import cn.tedu.charging.common.protocol.JsonResult;

import cn.tedu.charging.device.service.DeviceService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

//前后端分离开发
@RestController
@Slf4j
public class DeviceController {
    @Autowired
    private DeviceService deviceService;
    /**
     * 手机定位上报 查询附近充电站列表
     */
    @GetMapping("/device/station/near")
    public JsonResult<List<StationInfoVO>> nearStations(
            Double longitude,Double latitude,Double radius){
        //业务层组织封装所需的数据
        List<StationInfoVO> vos=deviceService.nearStations(longitude,latitude,radius);
        log.info("查询充电站列表,入参:{},出参:{}",radius,vos);
        return JsonResult.ok(vos);
    }
    //查询站场详情
    @GetMapping("/device/station/detail/{id}")
    public JsonResult<StationInfoVO> stationDetail(@PathVariable("id") Integer id/*,@PathVariable("name") String name*/){
        //log.info("name:{},id:{}",name,id);
        log.info("查询充电站详情,入参:{}",id);
        StationInfoVO vo=deviceService.stationDetail(id);
        JsonResult result = JsonResult.ok(vo);
        log.info("查询充电站详情,入参:{},结果:{}",id,result);
        return result;
    }
    //根据和订单约定的接口
    @PostMapping("/device/gun/status/update")
    public JsonResult<Boolean> updateGunStatus(@RequestBody GunStatusUpdateParam param){
        //执行更新 顺带 检查设备真实性(判断枪id是否能查询到枪数据)
        log.info("更新充电枪状态,入参:{}",param);
        Boolean success=deviceService.updateGunStatus(param);
        JsonResult result = JsonResult.ok(success);
        log.info("更新充电枪状态,入参:{},出参:{}",param,result);
        return result;
    }

}
